package cate.game.play.skill.passive.hero;

import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.passive.PassiveHandler;

import java.util.List;

/**
 * 生命值低于50%时，净化自身，为自身附加【超燃神炎】/n无冷却时间
 */
public class 超燃神炎PH extends PassiveHandler {

	private int 血量;

	private List<Integer> buffList;

	//血量=6000&buff=??#??
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		血量 = args.getInt("血量", 0);
		buffList = args.getIntList("buff");
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		buffList = XT.merge(buffList, args.getIntList("buff"));
	}

	private boolean settle;

	@Override
	public void onMoveDone(MoveCtx move, TimeActionCtx action) {
		if (settle) {
			return;
		}
		if (skill.owner.isDead()) {
			return;
		}
		if (skill.owner.attr.total().hpCurRate() > 血量) {
			return;
		}
		skill.owner.buff.tryDispelBad(action);
		if (XT.isNotBlank(buffList)) {
			for (Integer integer : buffList) {
				skill.owner.buff.tryAddByTid(action, integer);
			}
		}
		settle = true;
	}
}
